package com.yootk.main;

import com.yootk.aware.impl.YootkDataBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.Field;
import java.util.Arrays;

public class GetConfigLocations { // Spring容器的启动类
    private static final Logger LOGGER = LoggerFactory.getLogger(GetConfigLocations.class);
    public static void main(String[] args) throws Exception {
        AbstractXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/spring-base.xml") ;
        Class<?> clazz = context.getClass() ;
        Field field = getClassField(clazz,"configLocations") ;
        field.setAccessible(true);
        String[] confingLocations = (String[]) field.get(context) ;
        LOGGER.info("配置信息：{}", Arrays.toString(confingLocations));
    }
    public static Field getClassField(Class<?> clazz,String fieldNames){
        Field field = null ;
        while (field == null){
            try {
                field = clazz.getDeclaredField(fieldNames) ;
                break;
            } catch (NoSuchFieldException e) {
                clazz = clazz.getSuperclass() ;
                if (clazz == null){
                    break;
                }
            }
        }
        return  field ;
    }



}

